﻿using System;
using System.Collections.Generic;
using WEB.Core.Controls;
using Ext.Net;
using WEB.Core.Util;
using WEB.BLL.Services;
using WEB.BLL.Entities;

namespace WEB.APP.Modules.System
{
    public partial class Expertise : BasePage
    {
        public Expertise()
            : base(SCREENS.EXPERTISE, false)
        {

        }

        protected override void Page_Load(object sender, EventArgs e)
        {
            AddListControlAdd(tbs1);
            AddListControlDelete(tbs2);
            WindowEditor.SaveClick += WindowEditor_SaveClick;
            base.Page_Load(sender, e);
            grdMain.ColumnModel.Columns[1].Editable = IsEdit;
        }

        protected void WindowEditor_SaveClick(object sender, EventArgs e)
        {
            stMain.DataBind();
        }

        protected void stMain_OnRefreshData(object sender, StoreRefreshDataEventArgs e)
        {
            try
            {
                var lstFss_dirty_word = ExpertiseService.GetInstance().LoadData();
                if (null != lstFss_dirty_word)
                {
                    stMain.DataSource = lstFss_dirty_word;
                    stMain.DataBind();
                }
            }
            catch (Exception ex)
            {
                Notification(ex);
            }
        }
        public void btnNew_Click(object sender, DirectEventArgs e)
        {
            WindowEditor.Show();
        }
        [DirectMethod]
        public void Edit(long ID)
        {
            WindowEditor.Show(ID);
        }

        [DirectMethod]
        public void QuickEdit(decimal ID, string Name)
        {
            if (IsEdit)
            {
                try
                {
                    var _svc = ExpertiseService.GetInstance();
                    var _ett = new ExpertiseEntity() { ExpertiseId = ID, Name = Name };
                    _svc.Update(_ett);
                }
                catch (Exception ex)
                {
                    Notification(ex);
                    stMain.DataBind();

                }
            }
            else
            {
                X.Msg.Alert("Notification", "You do not have permission to edit.").Show();
                stMain.DataBind();
            }
        }
        [DirectMethod]
        public void Delete(decimal ID)
        {
            try
            {
                if (ID > 0 && IsDelete)
                {
                    var _ett = new ExpertiseEntity() { ExpertiseId = ID };
                    ExpertiseService.GetInstance().Delete(_ett);
                    stMain.DataBind();
                }
            }
            catch (Exception ex)
            {
                Notification(ex);
            }
        }
    }
}
